package pactera.tf.mq;

import java.util.List;
import java.util.Optional;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;

import pactera.tf.controller.ChatWebSocketController;
import pactera.tf.dataobj.ChatMsgDO;

@Component
public class ChatMsgConsumer {
	
	@Autowired
	ChatWebSocketController chatWebSocketController;
	/**
	 * 
	
	 * <p>Title: receiveMessage</p>  
	
	 * <p>Description:消费单条消息 </p>  
	
	 * @param chatmsg
	 */
    @KafkaListener(topics = {"chatMsg"})
    public void receiveMessage(String chatmsg){
    	JSONObject jsonObject = JSONObject.parseObject(chatmsg);
        //给指定的人发消息
    	chatWebSocketController.sendToUser(jsonObject.toJavaObject(ChatMsgDO.class));
        System.out.println(chatmsg);
    }
    
    
    /**
     * 
    
     * <p>Title: onMessage</p>  
    
     * <p>Description:批量消费消息 </p>  
    
     * @param crs
     */
    @KafkaListener(topics = "test")
    public void onMessage(List<String> crs) {
    }

   /**
    * 
   
    * <p>Title: consumer</p>  
   
    * <p>Description:读取消息topic，offset，key，value等信息 </p>  
   
    * @param consumerRecord
    */
	@KafkaListener(topics = "test")
    public void consumer(ConsumerRecord consumerRecord){
    }
}
